package io.adrainty.bolee.framework.mybatis.utils;

import org.apache.ibatis.executor.BatchResult;

import java.util.Arrays;
import java.util.List;

/**
 * <p>MybatisUtil</p>
 *
 * @author AdRainty
 * @version V1.0.0
 * @description MybatisUtil
 * @since 2025/8/15 11:10:39
 */

@SuppressWarnings("all")
public class MybatisUtil {

    private MybatisUtil() {}

    public static boolean isResultOk(List<BatchResult> batchResults) {
        for (BatchResult result : batchResults) {
            int[] updateCounts = result.getUpdateCounts();
            for (int count : updateCounts) {
                if (count <= 0) {  // 根据实际情况选择判断条件，有些情况下可能需要 count == 0
                    return false;  // 如果任何一个操作没有成功更新，则返回失败
                }
            }
        }
        return true;  // 所有操作都成功更新
    }

    public static <T> List<T> convertCheckIds(T[] checkIdArray) {
        if (checkIdArray == null || checkIdArray.length == 0) return List.of();
        return Arrays.stream(checkIdArray).toList();
    }

}
